<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="../../css/mui.min.css">
		<!--App自定义的css-->
		<link rel="stylesheet" type="text/css" href="../../css/app.css" />
		<link rel="stylesheet" type="text/css" href="../../css/global.css" />
		<script src="../../js/getURLParam.js"></script>
		<style>
			h5 {
				margin: 5px 7px;
			}
			body{
				background-color: #fff;	
			}
			.mui-content {
				background-color: #fff;
			}
		</style>
	</head>

	<body>
		<!--<header class="mui-bar mui-bar-nav headerstyle" >
			<a class="astyle" onclick="goback()"><img src="../../images/drawable-hdpi/head_back.png"/></a>
			<span id="title">故障码字典</span>
		<span class="focus" id="edit" onclick="goedit()">修改</span>
		</header>-->
		<div class="mui-content" style="padding-top:0px;width: 100%;">
			<div class="mui-content-padded" style="float: left;width: 100%;">
				<form class="mui-input-group">
					<div class="mui-input-row">
						<label>故障代码</label>
						<input type="text" placeholder="请输入故障代码" id="code">
					</div>
					<div class="mui-input-row">
						<label>SPN</label>
						<input type="text" placeholder="请输入SPN" id="spn">
					</div>
					<div class="mui-input-row">
						<label>FMI</label>
						<input type="text" placeholder="请输入FMI" id="fmi">
					</div>
				</form>
			</div>
			<div class="mui-content-padded" style="float: left;width: 100%;">
				<button type="button" class="mui-btn mui-btn-block mui-btn-primary" onclick="getFltCode()">搜索</button>
			</div>
			<div id="scroll" style="float: left;width: 100%;">
				<div id="list" style="overflow-y: scroll;height: 300px;"  >
				</div>
				
			</div>
			<!--<div id="scrolldetail" class="mui-scroll-wrapper" style="top: 200px;height: 350px;display: none;">
				<div class="mui-scroll" id="detail">
				</div>
			</div>-->
			<!--<div style="float: left;text-align: center;width: 100%;">
				<button style="border: none;color: #01AEE3;" onclick="openserver()">Quick Serve Online</button>
			</div>-->
		</div>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/getURLParam.js"></script>
		<script>
			mui.init({
				swipeBack: true //启用右滑关闭功能
			});
			mui('.mui-scroll-wrapper').scroll({
			});
			var sessionid=GetQueryString("sessionid");
	        var accountid=GetQueryString("accountid");
	        var proversion=GetQueryString("proversion");
	        //var isandroid=GetQueryString("isandroid");
	        //var tvalue=GetQueryString("tvalue");
	        function getFltCode(){
	        	var code = document.getElementById("code").value;
	        	var spn = document.getElementById("spn").value;
	        	var fmi = document.getElementById("fmi").value;
	        	if(code=="" && spn=="" && fmi==""){
	        		mui.toast("请填写数据后再搜索！")
	        		return false;
	        	}
	        	if((spn=="" || fmi=="") && code==""){
	        		mui.toast("spn,fmi 都不能为空！")
	        		return false;
	        	}
	        	
				var f = document.getElementById("list");
				//document.getElementById("scrolldetail").style.display="none";
				document.getElementById("list").style.display="";
				f.innerHTML="";
				var flt = "";
				//var car = document.getElementById("car");
				//var customer = document.getElementById("customer");
				mui.ajax('../../../APP/getFltCode',{
				data:{param:'{"proVersion":"'+proversion+'","accountId":"'+accountid+'","sessionid":"'+sessionid+'","data":{"tValue":"'+code+'","spn":"'+spn+'","fmi":"'+fmi+'"}}'},
				dataType:'jsonp',//服务器返回json格式数据
				type:'post',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；
				success:function(data){
					var jsonObj = window.JSON.parse(data);
					if(jsonObj.resultcode=="1"){
						//获取返回数据的data
						var resultdata = jsonObj.data;
						if(resultdata!=null&&resultdata.length>0){
							flt+='<ul class="mui-table-view">';
					  			for(var i=0;i<resultdata.length;i++){
									flt+='<li class="mui-table-view-cell"  onclick="getdetail('+"'"+rep(resultdata[i].fltcode)+"'"+','+rep(resultdata[i].fltspn)+','+rep(resultdata[i].fltfmi)+')"><span>'+resultdata[i].fltcode+'<span></li>'
					  			}
				  			flt+='</ul>';
				  			//flt+='</div>';
							f.innerHTML=flt;
						}else{
							f.innerHTML="<center>暂无数据</center>";
						}
						
					}else{
						f.innerHTML="请求出错!"+jsonObj.resultcode;
					}
				},
				error:function(xhr,type,errorThrown){
					//异常处理；
					//f.innerHTML="error";
				}
			});
			}
			function getdetail(code,spn,fmi){
	        	mui.ajax('../../../APP/getFltInfo',{
				data:{param:'{"proVersion":"'+proversion+'","accountId":"'+accountid+'","sessionid":"'+sessionid+'","data":{"fltCode":"'+code+'","spn":"'+spn+'","fmi":"'+fmi+'"}}'},
				dataType:'jsonp',//服务器返回json格式数据
				type:'post',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；
				success:function(data){
					var jsonObj = window.JSON.parse(data);
					if(jsonObj.resultcode=="1"){
						//获取返回数据的data
						var resultdata = jsonObj.data;
						var possiblereson1 = resultdata[0].possiblereson == null?"无":resultdata[0].possiblereson;
						var cleanstep1 = resultdata[0].cleanstep == null?"无":resultdata[0].cleanstep;
						if(resultdata!=null){
							flt="";
							flt+='<ul class="mui-table-view">';
							flt+='<li class="mui-table-view-cell" style="text-align: center;"><span>故障码：'+resultdata[0].fltcode+'</span><br /></li>';
							flt+='<li class="mui-table-view-cell" style="text-align: left;"><span>SPN：'+resultdata[0].fltspn+'</span><br />';
							flt+='<li class="mui-table-view-cell" style="text-align: left;"><span>FMI：'+resultdata[0].fltfmi+'</span><br />';
							flt+='<li class="mui-table-view-cell" style="text-align: left;"><span>故障颜色：'+resultdata[0].fltcor+'</span><br />';
							flt+='<li class="mui-table-view-cell" style="text-align: left;"><span>故障描述：'+resultdata[0].fltcon+'</span><br />';
							if(possiblereson1 != '无'){
							flt+='<li class="mui-table-view-cell" style="text-align: left;"><span>可能原因及诊断排除步骤：'+possiblereson1+'</span><br />';}
							if(cleanstep1!='无'){
				  			flt+='<li class="mui-table-view-cell" style="text-align: left;"><span>清除故障码的步骤：'+cleanstep1+'</span><br />';}
				  			flt+='<li class="mui-table-view-cell" style="text-align: left;"><span>故障风险：'+resultdata[0].fltrisk+'</span><br />';
				  			flt+='</li>';
				  			flt+='</ul>';
				  			//document.getElementById("scrolldetail").style.display=""
				  			//document.getElementById("detail").innerHTML=flt;
				  			document.getElementById("list").innerHTML=flt;
				  			//document.getElementById("list").style.display="none";
						}else{
							document.getElementById("list").innerHTML="暂无数据";
						}
						
					}else if(jsonObj.resultcode=="134"){
						mui.toast("故障码查询次数超过20次！请明天再次查询")
					}
				},
				error:function(xhr,type,errorThrown){
					//异常处理；
					f.innerHTML="error";
				}
			});
	        }
			function rep(str){
				var reg = /\s/g;
				var res = str.replace(reg, ""); 
				return res;

			}
			function goback(){
				//mui.back();
				if(isandroid!=undefined && isandroid=="1"){
					window.zidianbt.leftac();
				}else{
					window.webkit.messageHandlers.faultcode.postMessage("fltcodeback");					
				}
				
			}
			function openserver(){
				if(isandroid!=undefined && isandroid=="1"){
					window.goquickservice.serviceurl("https://quickserve.cummins.com");
				}else{
					window.webkit.messageHandlers.quickservice.postMessage("https://quickserve.cummins.com");			
				}
				
			}
		</script>
	</body>

</html>